package com.franklin.validation.core.entity;

import com.franklin.validation.core.annotations.ParamCheck;
import com.franklin.validation.core.annotations.ParamCheckSub;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * Description :
 * Create By: Franklin
 * Date : 2020/6/3 18:46
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ParamEntity implements Serializable {


    private static final long serialVersionUID = 4059444075523773368L;
    private String value;
    private boolean required;
    private String defaultValue;

    private int max;
    private int min;
    private String message;
    private String pattern;
    private Class type;

    public static ParamEntity getEntity(ParamCheck paramCheck){
        ParamEntity paramEntity = new ParamEntity();
        paramEntity.setValue(paramCheck.value());
        paramEntity.setDefaultValue(paramCheck.defaultValue());
        paramEntity.setRequired(paramCheck.required());
        paramEntity.setMax(paramCheck.max());
        paramEntity.setMin(paramCheck.min());
        paramEntity.setMessage(paramCheck.message());
        paramEntity.setPattern(paramCheck.pattern());
        paramEntity.setType(paramCheck.type());
        return paramEntity;
    }

    public static ParamEntity getEntity(ParamCheckSub paramCheck){
        ParamEntity paramEntity = new ParamEntity();
        paramEntity.setValue(paramCheck.value());
        paramEntity.setDefaultValue(paramCheck.defaultValue());
        paramEntity.setRequired(paramCheck.required());
        paramEntity.setMax(paramCheck.max());
        paramEntity.setMin(paramCheck.min());
        paramEntity.setMessage(paramCheck.message());
        paramEntity.setPattern(paramCheck.pattern());
        paramEntity.setType(paramCheck.type());
        return paramEntity;
    }
}
